Page({
  data: {
    countdownTime: 7, // 倒计时秒数
    timer: null       // 定时器对象
  },

  onLoad() {
    this.startCountdown();
  },

  // 启动倒计时
  startCountdown() {
    this.setData({ countdownTime: 7 });
    this.data.timer = setInterval(() => {
      const time = this.data.countdownTime - 1;
      if (time <= 0) {
        this.redirectToHome();
        return;
      }
      this.setData({ countdownTime: time });
    }, 1000);
  },

  // 用户点击跳过
  skipVideo() {
    clearInterval(this.data.timer);
    this.redirectToHome();
  },

  // 视频播放结束
  onVideoEnd() {
    clearInterval(this.data.timer);
    this.redirectToHome();
  },

  // 跳转到首页
  redirectToHome() {
    wx.redirectTo({
      url: '/Mall/pages/mall/mall'
    });
  },

  // 清理定时器
  onUnload() {
    clearInterval(this.data.timer);
  }
});